<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-sys__dict">
      <el-form
        :inline="true"
        :model="dataForm"
        @keyup.enter.native="getDataList()"
      >
        <el-form-item>
          <el-input
            v-model="dataForm.complainantName"
            placeholder="投诉人姓名"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="dataForm.complainantPhone"
            placeholder="联系电话"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="dataForm.islandId"
            placeholder="所属区域"
            clearable
            style="width: 100%"
          >
            <el-option
              v-for="item in scenicOptions"
              :key="item.id"
              :label="item.scenicName"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="dataForm.complainantType"
            placeholder="类型"
            clearable
            style="width: 100%"
          >
            <el-option
              v-for="(item, index) in types"
              :key="index"
              :label="item"
              :value="index"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="dataForm.stateArr"
            placeholder="状态"
            clearable
            multiple
            collapse-tags
            style="width: 100%"
          >
            <el-option
              v-for="(item, index) in types2"
              :key="index"
              :label="item"
              :value="index"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-date-picker
            v-model="value1"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t("query") }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button
            v-if="$hasPermission('scenic:complaintrecommendation:delete')"
            type="danger"
            @click="deleteHandle(id)"
            >{{ $t("deleteBatch") }}</el-button
          >
        </el-form-item>
        <el-form-item>
          <el-button
            v-if="$hasPermission('scenic:complaintrecommendation:export')"
            type="primary"
            @click="exportHandle()"
            >导出</el-button
          >
        </el-form-item>
      </el-form>
      <el-table
        v-loading="dataListLoading"
        :data="dataList"
        border
        @selection-change="dataListSelectionChangeHandle"
        @sort-change="dataListSortChangeHandle"
        style="width: 100%"
      >
        <el-table-column
          type="selection"
          :show-overflow-tooltip="true"
          align="center"
          width="50"
        ></el-table-column>
        <el-table-column
          prop="complainantObject"
          label="投诉对象"
          min-width="120"
          align="center"
        ></el-table-column>
        <!-- <el-table-column prop="complainantName" label="投诉人姓名" min-width="120" align="center"></el-table-column> -->
        <!-- <el-table-column prop="complainantObject" label="投诉对象" min-width="120" align="center"></el-table-column> -->
        <el-table-column
          prop="complainantId"
          label="投诉方ID"
          min-width="120"
          align="center"
        ></el-table-column>
        <!-- <el-table-column prop="islandName" label="所在区域" min-width="120" align="center"></el-table-column> -->
        <el-table-column
          prop="complainantPhone"
          label="联系电话"
          min-width="120"
          align="center"
        ></el-table-column>
        <!-- <el-table-column prop="content" label="投诉内容" :show-overflow-tooltip="true" min-width="120" align="center"></el-table-column>
            <el-table-column prop="reply" label="回复内容" :show-overflow-tooltip="true" min-width="120" align="center"></el-table-column> -->
        <!-- <el-table-column align="center" prop="pic">
                <template slot-scope="scope">
                    <el-image :src="scope.row.picList[0]" style="width:80px;height:80px"></el-image>
                </template>
</el-table-column> -->
        <el-table-column prop="complainantType" label="投诉类型" align="center">
          <template slot-scope="scope">
            {{ types[scope.row.complainantType] }}
          </template>
        </el-table-column>
        <el-table-column prop="state" label="状态 " align="center">
          <template slot-scope="scope">
            {{ types2[scope.row.state] }}
          </template>
        </el-table-column>
        <el-table-column
          prop="createDate"
          label="创建时间"
          align="center"
          min-width="150"
        >
        </el-table-column>
        <el-table-column
          :label="$t('handle')"
          fixed="right"
          :show-overflow-tooltip="true"
          align="center"
          min-width="150"
        >
          <template slot-scope="scope">
            <el-button
              v-if="
                $hasPermission('scenic:workorder:save') &&
                (scope.row.state == 4 ||
                  scope.row.state == 1 ||
                  scope.row.state == 0)
              "
              type="text"
              size="small"
              @click="addOrUpdateHandle(scope.row.id)"
              >派单</el-button
            >
            <el-button
              v-if="$hasPermission('scenic:complaintrecommendation:delete')"
              type="text"
              size="small"
              @click="deleteHandle(scope.row.id)"
              >{{ $t("delete") }}</el-button
            >
            <el-button
              v-if="
                $hasPermission('scenic:complaintrecommendation:update') &&
                scope.row.state == 0
              "
              type="text"
              size="small"
              @click="reply(scope.row.id)"
              >回复</el-button
            >
            <el-button
              v-if="$hasPermission('scenic:complaintrecommendation:info')"
              type="text"
              size="small"
              @click="lookDetail(scope.row)"
              >详情</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle"
      >
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update
        v-if="addOrUpdateVisible"
        ref="addOrUpdate"
        @refreshDataList="getDataList"
      ></add-or-update>
      <!-- 详情 -->
      <detail ref="lookDetail" v-if="lookDetailVisible" :data="data"> </detail>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from "@/mixins/view-module";
import AddOrUpdate from "./advice-add-or-update";
import detail from "./detail";
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      mixinViewModuleOptions: {
        getDataListURL: "/scenic/complaintrecommendation/page",
        getDataListIsPage: true,
        deleteURL: "/scenic/complaintrecommendation",
        deleteIsBatch: true,
        createdIsNeed: false,
        exportURL: "/scenic/complaintrecommendation/export",
      },
      value1: [],
      data: null,
      scenicOptions: [],
      types: [
        "功能故障",
        "景区意见",
        "产品建议",
        "预订咨询",
        "订单咨询",
        "其他",
      ],
      types2: [
        "待处理",
        "处理中",
        "派单中",
        "已解决",
        "继续投诉",
        "已撤销",
        "已评价",
      ],
      dataForm: {
        complainantType: "",
        complainantName: "",
        complainantPhone: "",
        islandId: "",
        startDate: "",
        endDate: "",
        state: null,
        stateArr: [],
      },
    };
  },
  components: {
    AddOrUpdate,
    detail,
  },
  watch: {
    value1(newval, oldval) {
      if (newval) {
        if (newval != oldval) {
          this.dataForm.startDate = newval[0];
          this.dataForm.endDate = newval[1];
        }
      } else {
        this.dataForm.startDate = "";
        this.dataForm.endDate = "";
      }
    },
    "dataForm.stateArr"(newval, oldval) {
      if (newval != oldval) {
        this.dataForm.state = newval.join(",");
      }
    },
  },
  created() {
    this.getScenicOptions();
  },
  mounted() {
    // let state = this.$route.query.state;
    // if (state) {
    //   this.dataForm.state = parseFloat(state);
    //   this.getDataList();
    // }
  },
  activated() {
    let state = this.$route.query.state;
    if (state != undefined) {
      this.dataForm.stateArr = JSON.parse(state);
      this.dataForm.state = this.dataForm.stateArr.join(",");
    } else {
      this.dataForm.stateArr = [];
      this.dataForm.state = "";
    }
    this.getDataList();
  },
  methods: {
    getScenicOptions() {
      this.$http
        .get("scenic/isscenic/selectScenicList", {})
        .then(({ data: res }) => {
          if (res.msg == "success") {
            this.scenicOptions = res.data;
          }
        });
    },
    lookDetail(item) {
      this.lookDetailVisible = true;
      this.data = item;
      this.$nextTick(() => {
        this.$refs.lookDetail.init();
      });
    },
    reply(id) {
      this.$prompt("请输入回复内容", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
      })
        .then(({ value }) => {
          this.$http
            .put("/scenic/complaintrecommendation/reply", {
              id: id,
              reply: value,
            })
            .then((res) => {
              this.$message({
                type: "success",
                message: "操作成功",
              });
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消输入",
          });
        });
    },
  },
};
</script>
